package com.example.yixueban.controller;

import com.example.yixueban.domain.User;
import com.example.yixueban.resp.CommonResp;
import com.example.yixueban.service.AdminServiceImpl;
import com.example.yixueban.service.UserServiceImpl;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * User: Wang YiHan
 * Date: 2021/8/5 10:05
 * Email: 783096044@qq.com
 * File_Name: null.java
 **/
@ResponseBody
@RestController
@RequestMapping("/admin")
public class AdminController {
    @Resource
    private AdminServiceImpl adminService;
    @Resource
    private UserServiceImpl userService;

    @GetMapping("/getAllUsers")
    public CommonResp getAllUsers(){
        CommonResp<List<User>> resp = new CommonResp<>();
        System.out.println("1");
        List<User> userList = adminService.getAllUsers();
        System.out.println("2");
        resp.setContent(userList);
        System.out.println("3 ");


        return resp;
    }
    @GetMapping("/findUser")
    public CommonResp findUser(String name) {
        System.out.println("name is "+name);
        CommonResp<List<User>> resp = new CommonResp<>();
        List<User> list = adminService.getUsersByName(name);
        resp.setContent(list);
        return resp;

    }



}
